<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui">
 
    <h:form id="UsersListForm"> 

        <p:panel header="#{MyBundle.ListUsersTitle}">
            <p:contextMenu for="datalist">  
                <p:menuitem id="createMenuItem" icon="ui-icon-plus" value="#{MyBundle.Create}" onclick="document.getElementById('UsersListForm:createButton').click();"/>
                <p:menuitem id="readMenuItem" icon="ui-icon-search" value="#{MyBundle.View}" onclick="document.getElementById('UsersListForm:viewButton').click();"/>
                <p:menuitem id="updateMenuItem" icon="ui-icon-pencil" value="#{MyBundle.Edit}" onclick="document.getElementById('UsersListForm:editButton').click();"/>
                <p:menuitem id="deleteMenuItem" icon="ui-icon-trash" value="#{MyBundle.Delete}" onclick="document.getElementById('UsersListForm:deleteButton').click();"/>
            </p:contextMenu>
            <p:dataTable id="datalist"
                         value="#{usersController.items}"
                         var="item"
                         rowKey="#{item.user}"
                         paginator="true"
                         rows="10"
                         rowsPerPageTemplate="10,20,30,40,50"
                         selectionMode="single"
                         selection="#{usersController.selected}">

                <p:ajax event="rowSelect"   update=":UsersListForm:createButton :UsersListForm:viewButton :UsersListForm:editButton :UsersListForm:deleteButton"/>
                <p:ajax event="rowUnselect" update=":UsersListForm:createButton :UsersListForm:viewButton :UsersListForm:editButton :UsersListForm:deleteButton"/>
                <p:ajax event="rowDblselect" onsuccess="document.getElementById('UsersListForm:viewButton').click();"/>

                <p:column sortBy="#{item.user}" filterBy="#{item.user}">
                    <f:facet name="header">
                        <h:outputText value="#{MyBundle.ListUsersTitle_user}"/>
                    </f:facet>
                    <h:outputText value="#{item.user}"/>
                </p:column>

                <!--
                <p:column sortBy="#{item.password}" filterBy="#{item.password}">
                    <f:facet name="header">
                        <h:outputText value="#{MyBundle.ListUsersTitle_password}"/>
                    </f:facet>
                    <h:outputText value="#{item.password}"/>
                </p:column>
                -->

                <p:column sortBy="#{item.email}" filterBy="#{item.email}">
                    <f:facet name="header">
                        <h:outputText value="#{MyBundle.ListUsersTitle_email}"/>
                    </f:facet>
                    <h:outputText value="#{item.email}"/>
                </p:column>


                <p:column sortBy="#{item.superadmin}" filterBy="#{item.superadmin}">
                    <f:facet name="header">
                        <h:outputText value="#{MyBundle.ListUsersTitle_superadmin}"/>
                    </f:facet>
                    <h:outputText value="#{item.superadmin}"/>
                </p:column>


                <p:column sortBy="#{item.lastConnection}" filterBy="#{item.lastConnection}">
                    <f:facet name="header">
                        <h:outputText value="#{MyBundle.ListUsersTitle_lastConnection}"/>
                    </f:facet>
                    <h:outputText value="#{item.lastConnection}">
                        <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                    </h:outputText>
                </p:column>


                <p:column sortBy="#{item.status}" filterBy="#{item.status}">
                    <f:facet name="header">
                        <h:outputText value="#{MyBundle.ListUsersTitle_status}"/>
                    </f:facet>
                    <h:outputText value="#{item.status}"/>
                </p:column>


            </p:dataTable>

            <p:commandButton id="createButton"                             icon="ui-icon-plus"   value="#{MyBundle.Create}" actionListener="#{usersController.prepareCreate}" update=":UsersCreateForm" oncomplete="UsersCreateDialog.show()"/>
            <p:commandButton id="viewButton"   style="visibility: hidden;" icon="ui-icon-search" value="#{MyBundle.View}" update=":UsersViewForm" oncomplete="UsersViewDialog.show()" disabled="#{empty usersController.selected}"/>
            <p:commandButton id="editButton"   style="visibility: hidden;" icon="ui-icon-pencil" value="#{MyBundle.Edit}" update=":UsersEditForm" oncomplete="UsersEditDialog.show()" disabled="#{empty usersController.selected}"/>
            <p:commandButton id="deleteButton" style="visibility: hidden;" icon="ui-icon-trash"  value="#{MyBundle.Delete}" actionListener="#{usersController.delete}" update=":growl,datalist" disabled="#{empty usersController.selected}">
                <p:confirm header="#{MyBundle.ConfirmationHeader}" message="#{MyBundle.ConfirmDeleteMessage}" icon="ui-icon-alert"/>
            </p:commandButton>

        </p:panel>
        <ui:include src="/WEB-INF/include/confirmation.xhtml"/>
    </h:form>

</ui:composition>